package com.wondream.java.io.example;

import java.io.*;

public class BufferedInputOutputStreamTest {

    public static void main(String[] args) {
        try{
            File source = new File("./logs/data.zip");
            File dest = new File("./logs/copyData.zip");
            copyFile(source, dest);
        } catch (Exception e){}
    }

    public static void copyFile(File src, File des){
        if(src==null){return;}
        if(des==null){return;}
        // 创建缓冲流
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        try {
            bis = new BufferedInputStream(new FileInputStream(src));
            bos = new BufferedOutputStream(new FileOutputStream(des));
            int dataLen = -1;
            byte[] buffer = new byte[1024*100];
            while((dataLen = bis.read(buffer))!=-1){
                bos.write(buffer, 0, dataLen);
            }
            bos.flush();
        } catch (Exception e){

        } finally {
            try {
                if(bis!=null){
                    bis.close();
                    bis = null;
                }
                if(bos!=null){
                    bos.close();
                    bos = null;
                }
            } catch (Exception e){}
        }
    }
}
